#!/bin/bash

# Test sockfd connection

. ./common

trap "_uninit; exit \$status" 0 1 2 3 15
_uninit()
{
	for i in `seq 1 7`; do
		_cleanup_machine_simulation $i
	done
}

_need_to_be_root

for i in `seq 0 9`; do
	_start_sheep $i
done

_wait_for_sheep 10

_cluster_format -c 6

_vdi_create test 40M
_random | $DOG vdi write test &

sleep 2
# Test write timeout
for i in `seq 1 4`; do
	_simulate_machine_down $i
done

# wait for dog to finish
wait
_wait_for_sheep_recovery 0

$DOG vdi read test | md5sum > $STORE/csum.1

for i in `seq 0 9`; do
	$DOG vdi object location -i $i test
done

for i in 10 11 12; do
	_start_sheep $i
done

_wait_for_sheep_recovery 0

# Test read timeout
$DOG vdi read test | md5sum > $STORE/csum.2 &
for i in `seq 5 7`; do
	_simulate_machine_down $i
done
wait

diff -u $STORE/csum.1 $STORE/csum.2
status=0
